package com.example.hxds.mis.api.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.example.hxds.common.util.PageUtils;
import com.example.hxds.common.util.R;
import com.example.hxds.mis.api.controller.form.*;
import com.example.hxds.mis.api.feign.VoucherServiceApi;
import com.example.hxds.mis.api.service.VoucherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @Author XUYANG
 * @Date 2024-04-08 18:58
 */
@Service
@Slf4j
public class VoucherServiceImpl implements VoucherService {
    @Resource
    private VoucherServiceApi voucherServiceApi;
    @Override
    public PageUtils searchVoucherByPage(SearchVoucherByPageForm form) {
        R r=voucherServiceApi.searchVoucherByPage(form);
        HashMap map=(HashMap) r.get("result");
        PageUtils res= BeanUtil.toBean(map,PageUtils.class);
        return res;
    }

    @Override
    @Transactional
    @LcnTransaction
    public int insertVoucher(InsertVoucherForm form) {
        R r=voucherServiceApi.insertVoucher(form);
        int rows= MapUtil.getInt(r,"rows");
        return rows;
    }

    @Override
    @Transactional
    @LcnTransaction
    public int updateVoucherStatus(UpdateVoucherStatusForm form) {
        R r=voucherServiceApi.updateVoucherStatus(form);
        int rows=MapUtil.getInt(r,"rows");
        return rows;
    }

    @Override
    public int deleteVoucherByIds(DeleteVoucherByIdsForm form) {
        R r=voucherServiceApi.deleteVoucherByIds(form);
        int rows=MapUtil.getInt(r,"rows");
        return rows;
    }
}
